import { Message } from '@arco-design/web-react';
import { apiSyncOperateStartAndStop } from '../../../api';
import { CardDetail } from '../refresh/types';
import LoadingMask from '../../../components/loadingMask';
// 开关机
export async function handleOpenOrStop(record: CardDetail,callBack?: Function) {
    LoadingMask.show('正在操作...');
    
    try {
      let res = await apiSyncOperateStartAndStop({
        form: {
          pageNum:1,
          pageSize:12,
          ids: [record.id!],
          taskOperationType: record.switchStatus === 'Y' ? 'stop' : 'open',
        },
        queryParams: {
          pageNum:1,
          pageSize:12,
          orderByColumn: 'id',
          isAsc: 'desc',
          params: {},
          exportName: '卡片操作',
        },
      });
      let data = res.data;
      if (data.code === 200) {
        callBack && callBack(data.data.id!.toString())
      } else {
        Message.warning(data.msg ?? '操作失败');
      }
    } catch (e: any) {
      Message.error(e.message ?? '操作失败');
    } finally {
      LoadingMask.hide();
    }
  }